package com.bw.zg2.utils

import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import android.text.TextUtils

/**
 *
 * @ClassName: SpUtil
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/18 11:19 AM
 * @Version: 1.0
 */
class SpUtil {
    companion object {
        private lateinit var sp: SharedPreferences
        fun init(context: Context) {
            sp = context.getSharedPreferences("shop", Application.MODE_PRIVATE)
        }

        fun putString(key: String, value: String) {
            sp.edit().putString(key, value).commit()
        }

        fun getString(key: String): String {
            return sp.getString(key, "").toString()
        }


        fun putInt(key: String, value: Int) {
            sp.edit().putInt(key, value).commit()
        }

        fun getInt(key: String): Int {
            return sp.getInt(key, 0)
        }

        fun isLogin(): Boolean {
            return !TextUtils.isEmpty(getString("token"))
        }

        fun clearData(){
            sp.edit().clear().commit()
        }
    }
}